package com.wodan.zhongjinjicang.common.orm.bytesconverter.impl;

import org.apache.commons.lang.StringUtils;

import com.wodan.zhongjinjicang.common.orm.bytesconverter.Converter;

/**
 * string 类型转换器
 * 
 * @ClassName: StringConverter
 * @author Administrator
 * @date 2015-1-10 下午3:51:05
 * @history
 * 
 */
public class BooleanConverter implements Converter {

	private static final String TRUE = "1";

	private static final String FALSE = "0";

	@Override
	public Object fromString(String str) {
		if (TRUE.equals(str)) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	@Override
	public String toString(Object obj) {
		Boolean b = (Boolean) obj;
		if (b.booleanValue()) {
			return TRUE;
		} else {
			return FALSE;
		}
	}

	@Override
	public boolean isNullOrEmpty(Object obj) {
		if (obj == null) {
			return true;
		}

		if (StringUtils.isBlank(String.valueOf(obj))) {
			return true;
		} else {
			return false;
		}
	}
}
